'''
Created on Jan 11, 2013

@author: trananh
'''

class KTHDataSet(object):
    """
    classdocs
    """


    def __init__(self):
        """
        Constructor
        """
        self.itemsMap = dict()
    
    def getAllItems(self):
        """
        Returns a big list of all items.
        """
        allitems = list()
        for persons in self.itemsMap.values():
            for segments in persons.values():
                allitems.extend(segments.values())
        return allitems
    
    def getItemsByPersonIDs(self, personids):
        """
        Returns a big list of all items with the given personids.
        
        PARAMETER(S):
            personids - list of person ids.
        """
        pitems = list()
        for pid in personids:
            for persons in self.itemsMap.values():
                if persons.has_key(pid):
                    segments = persons[pid]
                    pitems.extend(segments.values())
        return pitems
    
    def hasItem(self, label, personid, segmentid):
        return self.itemsMap.has_key(label) and self.itemsMap[label].has_key(personid) \
            and self.itemsMap[label][personid].has_key(segmentid)
    
    def getItem(self, label, personid, segmentid):
        return self.itemsMap[label][personid][segmentid]
    
    def addItem(self, item):
        """
        Adds an item, keyed by the verb label and the actor's id.
        
        PARAMETER(S):
            item - item to be added.
        """
        label = item.label;
        personid = item.attributes['personid']
        segmentid = item.attributes['segmentid']
        if not self.itemsMap.has_key(label):
            self.itemsMap[label] = dict()
        persons = self.itemsMap[label]
        if not persons.has_key(personid):
            persons[personid] = dict()
        segments = persons[personid]
        segments[segmentid] = item
        